{extend name="common/base" /}
{block name='title'}添加参数 - 参数管理{/block}

{block name="body"}
<article class="clearfix pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-set-add">
        <input name="front_id" type="hidden" value="{$front_id}">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="title" name="title">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>副标题：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="title_en" name="title_en">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3">图片：</label>
            <div class="form-controls col-xs-8 col-sm-9" >
                <div id="uploadLists" ></div>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file"  name="btn-upload" id="btn-upload" class="input-file">
                </span>
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>简介：</label>
            <div class="form-controls col-xs-8 col-sm-9 ">
                <textarea name="summary" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>首页显示：</label>
            <div class="form-controls col-xs-8 col-sm-9 skin-minimal " >
                <div class="radio-box">
                    <input name="is_index" type="radio" value="1" id="sex-1" >
                    <label for="sex-1">是</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-2" value="2" name="is_index" checked>
                    <label for="sex-2">否</label>
                </div>
    
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>内容：</label>
            <div class="form-controls col-xs-8 col-sm-9" >
                <script id="articleEditor" type="text/plain" style="width:100%;height:400px;"></script>
            </div>
        </div>
        
       
        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
    
    <input name="uploadImage" type="hidden" value="{:url('upload/uploadImage')}">
    <input name="image" type="hidden" >
    <input name="thumb" type="hidden" >
</article>
{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="__JS__/main.js"></script>

<script type="text/javascript">
    $(function(){
        /* 通过iCheck插件，美化checkbox */
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        
        var ue = UE.getEditor('articleEditor');

        /* 表单验证，提交 */
        $("#form-set-add").validate({
            rules:{
                set_name:{
                    required:true,
                },
                type:{
                    required:true,
                },
                set_key:{
                    required:true,
                }
                
            },
            messages: {
              password2: {
                equalTo: "两次密码不一致",
              },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                
                var front_id = $("input[name='front_id']").val();
                var title = $("input[name='title']").val();
                var title_en = $("input[name='title_en']").val();
                var thumb = $("input[name='thumb']").val();
                var image = $("input[name='image']").val();
                var summary = $("textarea[name='summary']").val();
                var content = ue.getContent();
                var is_index = $("input[name='is_index']:checked").val();
                
                $.ajax({
                    type: 'post', // 提交方式 get/post
                    url: "{:url('info/add')}", // 需要提交的 url
                    data: {
                        'front_id': front_id,
                        'title': title,
                        'title_en': title_en,
                        'thumb': thumb,
                        'image' : image,
                        'summary' : summary,
                        'content' : content,
                        'is_index' : is_index,
                        
                    },
                    dataType: 'json',
                    success: function(ret) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        //console.log(ret);return false;
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                
            }
        });
    });
    
    $("select[name='type']").bind('change',function(){
        var val = $(this).val();
        //console.log(val);return false;
        $(".set_type").hide();
        $("#type"+val).show();
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}
